<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/6/12
 * Time: 16:49
 */
namespace App\Modules\BackCost\Models;
use Illuminate\Database\Eloquent\Model;

class HbGzh extends Model {
    protected $table = 'promotion_groups_hb_gzhs';

    protected $fillable = ['id','distribution_channel_id','gzh_name','appid','start_time','end_time','created_at','updated_at'];

    public static function getSearch($params,$is_all=true){
        $obj = self::orderBy('id','desc');
        if(isset($params['start_time']) && $params['start_time']) {
            $obj->where('start_time','>=',$params['start_time']);
        }
        if(isset($params['end_time']) && $params['end_time']) {
            $obj->where('end_time','<=',$params['end_time']);
        }
        if($is_all){
            return $obj->get();
        }else{
            return $obj->paginate(20);
        }

    }

    public static function addOne($params) {
        return self::create($params);
    }
}